﻿using System;
using System.ComponentModel;
using FXSStation.Modules.SharedInfrastructureModule.BusinessClasses.Accounts;
using FXSStation.Modules.SharedInfrastructureModule.BusinessClasses.Currency;

namespace FXSStation.Modules.SharedInfrastructureModule.BusinessClasses.Orders
{
    [Serializable]
    public class OrderBase: INotifyPropertyChanged
    {
        private DateTime _timeStamp;
        public DateTime TimeStamp
        {
            get { return _timeStamp; }
            set 
            {
                if (_timeStamp != value)
                {
                    _timeStamp = value;
                    RaisePropertyChanged("TimeStamp");
                }
            }
        }
        
        private Account _account;
        public Account Account
        {
            get { return _account; }
            set
            {
                if (_account != value)
                {
                    _account = value;
                    RaisePropertyChanged("Account");
                }
            }
        }
        
        private CurrencyEnum _currencySymbol;
        public CurrencyEnum CurrencySymbol
        {
            get { return _currencySymbol; }
            set
            {
                if (_currencySymbol != value)
                {
                    _currencySymbol = value; 
                    RaisePropertyChanged("CurrencySymbol");
                }
            }
        }
        
        private bool _isClosed;
        public bool IsClosed
        {
            get { return _isClosed; }
            set
            {
                if (_isClosed != value)
                {
                    _isClosed = value;
                    RaisePropertyChanged("IsClosed");
                }
            }
        }
        
        private int _volume;
        public int Volume
        {
            get { return _volume; }
            set {
                if (_volume != value)
                {
                    _volume = value;
                    RaisePropertyChanged("Volume");
                }
            }
        }
        
        private OrderType _type;
        public OrderType Type
        {
            get { return _type; }
            set {
                if (_type != value)
                {
                    _type = value;
                    RaisePropertyChanged("Type");
                }
            }
        }
        
        private decimal _profit;
        public decimal Profit
        {
            get { return decimal.Round(_profit,4); }
            set {
                if (_profit != value)
                {
                    _profit = value;
                    RaisePropertyChanged("Profit");
                }
            }
        }

        private decimal _openingPrice;
        public decimal OpeningPrice
        {
            get { return decimal.Round(_openingPrice, 4); }
            set
            {
                if (_openingPrice != value)
                {
                    _openingPrice = value;
                    RaisePropertyChanged("OpeningPrice");
                }
            }
        }

        private decimal _closingPrice;
        public decimal ClosingPrice
        {
            get { return decimal.Round(_closingPrice, 4); }
            set
            {
                if (_closingPrice != value)
                {
                    _closingPrice = value;
                    RaisePropertyChanged("ClosingPrice");
                }
            }
        }

        private decimal _currentPrice;
        public decimal CurrentPrice
        {
            get { return decimal.Round(_currentPrice, 4); }
            set
            {
                if (_currentPrice != value)
                {
                    _currentPrice = value;
                    RaisePropertyChanged("CurrentPrice");
                }
            }
        }

        private decimal _lastChangePrice;
        public decimal LastChangePrice
        {
            get { return decimal.Round(_lastChangePrice, 4); }
            set
            {
                if (_lastChangePrice != value)
                {
                    _lastChangePrice = value;
                    RaisePropertyChanged("LastChangePrice");
                }
            }
        }

        public OrderBase()
        {

        }

        /// <param name="timeStamp">Date when the Order is created</param>
        /// <param name="orderType">The Type of the Order</param>
        /// <param name="volume">Number of lots used</param>
        /// <param name="currencySymbol">CurrencyPair that the Order was made against</param>
        /// <param name="openingPrice">The price at which the order was made</param>
        public OrderBase(DateTime timeStamp, OrderType orderType, int volume, CurrencyEnum currencySymbol, decimal openingPrice)
        {
            this._timeStamp = timeStamp;
            this._type = orderType;
            this._volume = volume;
            this._openingPrice = openingPrice;
            this._lastChangePrice = openingPrice;
            this._currencySymbol = currencySymbol;
        }

        /// <param name="timeStamp">DateTime when the Order is created</param>
        /// <param name="account">The Account making the Order</param>
        /// <param name="orderType">The Type of the Order</param>
        /// <param name="volume">Number of lots used</param>
        /// <param name="currencySymbol">CurrencyPair that the Order was made against</param>
        /// <param name="openingPrice">The price at which the order was made</param>
        public OrderBase(DateTime timeStamp, Account account, OrderType orderType, int volume, CurrencyEnum currencySymbol, decimal openingPrice)
        {
            this._timeStamp = timeStamp;
            this._account = account;
            this._type = orderType;
            this._volume = volume;
            this._currencySymbol = currencySymbol;
            this._openingPrice = openingPrice;
            this._lastChangePrice = openingPrice;
        }

        #region INotifyPropertyChanged Members
        [field: NonSerialized]
        public event PropertyChangedEventHandler PropertyChanged;
        public void RaisePropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

    }
}
